﻿Imports Microsoft.VisualBasic
Imports System.ComponentModel
Imports System.Data
Public Class Evaluaciones
    Inherits BDDatos
    Public PUNTUALIDAD As Decimal
    Public IMAG_PRES_PERS As Decimal
    Public EXPRE_VERB_ESC As Decimal
    Public MAN_APLI_OFFI As Decimal
    Public RESPONSABILIDAD As Decimal
    Public INTE_EQUI_TRA As Decimal
    Public RECOMENDACIONES_EVA As String
    Public CONSIDERA As Integer
    Public RAZ_CONSI As String
    Public EVALUADOR As String
    Public ID_OFER_EST As Integer
    Public TIP_EVAL As String
    Public CARGO_EVAL As String

    Public Function Insert() As String
        Me.Conectar()
        Me.ComenzarTransaccion()
        Try
            Me.querystring = "INSERT INTO EVALUACION(PUNTUALIDAD,IMAG_PRES_PERS,EXPRE_VERB_ESC,MAN_APLI_OFFI,RESPONSABILIDAD,INTE_EQUI_TRA,RECOMENDACIONES_EVA,CONSIDERA,RAZ_CONSI,EVALUADOR,ID_OFER_EST,TIP_EVAL,CARGO_EVAL)" & _
                "VALUES(:PUNTUALIDAD,:IMAG_PRES_PERS,:EXPRE_VERB_ESC,:MAN_APLI_OFFI,:RESPONSABILIDAD,:INTE_EQUI_TRA,:RECOMENDACIONES_EVA,:CONSIDERA,:RAZ_CONSI,:EVALUADOR,:ID_OFER_EST,:TIP_EVAL,:CARGO_EVAL)"
            Me.CrearComando(querystring)
            AsignarParametroCadena(":PUNTUALIDAD", PUNTUALIDAD)
            AsignarParametroCadena(":IMAG_PRES_PERS", IMAG_PRES_PERS)
            AsignarParametroCadena(":EXPRE_VERB_ESC", EXPRE_VERB_ESC)
            AsignarParametroCadena(":MAN_APLI_OFFI", MAN_APLI_OFFI)
            AsignarParametroCadena(":RESPONSABILIDAD", RESPONSABILIDAD)
            AsignarParametroCadena(":INTE_EQUI_TRA", INTE_EQUI_TRA)
            AsignarParametroCadena(":RECOMENDACIONES_EVA", RECOMENDACIONES_EVA)
            AsignarParametroCadena(":CONSIDERA", CONSIDERA)
            AsignarParametroCadena(":RAZ_CONSI", RAZ_CONSI)
            AsignarParametroCadena(":EVALUADOR", EVALUADOR)
            AsignarParametroCadena(":ID_OFER_EST", ID_OFER_EST)
            AsignarParametroCadena(":TIP_EVAL", TIP_EVAL)
            AsignarParametroCadena(":CARGO_EVAL", CARGO_EVAL)
            Me.num_reg = Me.EjecutarComando
            Me.Msg = MsgOk
            Me.ConfirmarTransaccion()
            Dim obj As New NotificacionesEmail
            Dim dt As DataTable = GetOfertaNotEval(ID_OFER_EST, TIP_EVAL)
            Dim plantilla As String = Cargar_Plantilla(dt, "EVALUACION")
            Me.Msg += " " & obj.Correo_Evaluacion(ID_OFER_EST, TIP_EVAL, dt, plantilla)
        Catch ex As Exception
            Me.CancelarTransaccion()
            Me.lErrorG = True
            Me.Msg = "Error: " & ex.Message
        Finally
            Me.Desconectar()
        End Try
        Return Me.Msg
    End Function
    Public Function GetbyPK(ByVal ID As String, ByVal estado As String) As DataTable
        Me.Conectar()
        Me.querystring = "SELECT * FROM EVALUACION WHERE ID_OFER_EST=:ID and Tip_Eval=:ESTADO"
        Me.CrearComando(querystring)
        Me.AsignarParametroCadena(":ID", ID)
        Me.AsignarParametroCadena(":ESTADO", estado)
        Dim dt As DataTable = EjecutarConsultaDataTable()
        Me.Desconectar()
        Return dt
    End Function
    <DataObjectMethodAttribute(DataObjectMethodType.Select, True)> _
    Public Function GetOfertaNotEval(ByVal Oferta As String, ByVal tip_eval As String) As DataTable
        Me.querystring = "Select * from veval_oferta where ID_OFER_EST=:Oferta and TIP_EVAL=:TIP_EVAL"
        CrearComando(querystring)
        Me.AsignarParametroCadena(":Oferta", Oferta)
        Me.AsignarParametroCadena(":TIP_EVAL", tip_eval)
        'Throw New Exception(vComando.CommandText)
        Dim dt As DataTable = EjecutarConsultaDataTable()
        Return dt
    End Function
    Public Function Cargar_Plantilla(ByVal datos As DataTable, ByVal Nomb_Plantilla As String) As String
        Dim dtc As DataTable = GetPorNomb(Nomb_Plantilla)
        Dim m As String = ""
        If dtc.Rows.Count > 0 Then
            m = dtc.Rows(0)("Cuerpo").ToString
        End If
        Return m
    End Function
    <DataObjectMethodAttribute(DataObjectMethodType.Select, True)> _
    Public Function GetPorNomb(ByVal Corr_Nomb As String) As DataTable
        querystring = "SELECT * FROM Correos Where Nom_Correo=:Corr_Nomb "
        Me.CrearComando(querystring)
        AsignarParametroCadena(":Corr_Nomb", Corr_Nomb)
        Dim dataTb As DataTable = Me.EjecutarConsultaDataTable()
        Return dataTb
    End Function
End Class
